package eom.example.local.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author X.I.O
 * @title: CacheUtils
 * @projectName spring-boot-local
 * @description: TODO
 * @date 2021/11/13 15:30
 *
 * 缓存工具类
 */
public class CacheUtils {

    private static Map<String, Object> objectMap;

    public static <T> void put(String key, List<T> ts){
        Map<String, Object> map=getObjectMap();
        map.put(key,ts);
    }

    public static <T> void put(Class<T> cls,List<T> ts){
        String objName=cls.getName();
        put(objName,ts);
    }

    public static <T> List<T> getList(Class<T> cls){
        String objName=cls.getName();
        return getList(objName);
    }

    public static <T> List<T> getList(String key){
        Map<String, Object> map=getObjectMap();
        Object value=map.get(key);
        if(value==null){
            return null;
        }else {
            return (List<T>) value;
        }
    }

    public static void put(String key,Object value){
        Map<String, Object> map=getObjectMap();
        map.put(key,value);
    }

    public static Object get(String key){
        Map<String, Object> map=getObjectMap();
        return map.get(key);
    }

    private static Map<String, Object> getObjectMap(){
        if(objectMap==null){
            objectMap=new HashMap<>(10000);
        }
        return objectMap;
    }
}
